package de.laures.cewolf.example;

import java.util.Date;
import java.util.Map;

import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultIntervalCategoryDataset;

import de.laures.cewolf.AbstractDatasetProducer;
import de.laures.cewolf.DatasetProduceException;
import de.laures.cewolf.links.CategoryItemLinkGenerator;
import de.laures.cewolf.tooltips.CategoryToolTipGenerator;
import de.laures.cewolf.tooltips.CommonToolTip;
import de.laures.cewolf.tooltips.ToolTip;

public class BarData extends AbstractDatasetProducer implements CategoryToolTipGenerator,
		CategoryItemLinkGenerator {

	@Override
	public String getProducerId() {
		return "BarDataProducer";
	}

	@Override
	public boolean hasExpired(Map params, Date since) {
		return false;
	}

	@Override
	public Object produceDataset(Map params) throws DatasetProduceException {
		final String[] categories = { "apples", "pies", "bananas", "oranges" };
		final String[] seriesNames = { "Peter", "Helga", "Franz", "Olga" };
		final Integer[][] startValues = new Integer[seriesNames.length][categories.length];
		final Integer[][] endValues = new Integer[seriesNames.length][categories.length];
		for (int series = 0; series < seriesNames.length; series++) {
			for (int i = 0; i < categories.length; i++) {
				int y = (int) (Math.random() * 10 + 1);
				startValues[series][i] = new Integer(y);
				endValues[series][i] = new Integer(y + (int) (Math.random() * 10));
			}
		}
		DefaultIntervalCategoryDataset ds = new DefaultIntervalCategoryDataset(seriesNames,
				categories, startValues, endValues);
		return ds;
	}

	@Override
	public ToolTip generateToolTip(CategoryDataset data, int series, int item, String tt) {
		Object obj1 = data.getColumnKey(series);
		Object obj2 = data.getRowKey(series);
		Object obj3 = data.getValue(series, item);
		CommonToolTip tip = new CommonToolTip(obj2 + " " + obj1 + " " + obj3);
		return tip;
	}

	@Override
	public String generateLink(Object dataset, int series, Object category) {
		return "javascript:void(0);";
	}

}
